/*
 * @Author: 郭招娣 10615594+guo-zhaodi@user.noreply.gitee.com
 * @Date: 2022-10-25 15:01:43
 * @LastEditors: 郭招娣 10615594+guo-zhaodi@user.noreply.gitee.com
 * @LastEditTime: 2022-10-26 08:07:15
 * @FilePath: \宏烨找房\user\demo\src\store\loginReducer.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { fetch_data } from "./loginAction"
import { no_login } from "./loginAction"

const initState = {
    user: JSON.parse(localStorage.getItem('user') )|| {} ,
    token: '',
    isLogin:true
}

export const loginReducer = (state = initState, action) => {
    switch (action.type) {
        case fetch_data: {
            console.log(action.payload)
            localStorage.setItem('user', JSON.stringify(action.payload))
            localStorage.setItem('token', action.aaa);

            return {
                ...state,
                user: action.payload,
                token: action.token,
            }
        }
        case no_login: {
            console.log(action.payload)
            localStorage.clear()
            // dispatch(push("/login", action.payload));
            // window.history.push('/login')
            // localStorage.setItem('bbb', action.bbb);

            return {
                ...state,
                isLogin:false,
            }
        }
        default:
            return state
    }
} 
